package com.tanhua.server.service;

import com.tanhua.dubbo.api.UserLocationApi;
import com.tanhua.model.vo.ErrorResult;
import com.tanhua.server.exception.BusinessException;
import com.tanhua.server.interceptor.UserHolder;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

/**
 * @author Xiao
 * @version 1.0
 * @description 百度Controller
 * @date 2021/10/31
 */
@Service
@Slf4j
public class BaiduService {
    @DubboReference
    private UserLocationApi userLocationApi;

    /**
     * 百度-上报地理信息
     * @param latitude  纬度
     * @param longitude 经度
     * @param addrStr
     */
    public void location(Double latitude, Double longitude, String addrStr) {
        log.info("纬度:{}, 经度:{}, 地址:{}", latitude, longitude, addrStr);
        Long userId = UserHolder.getUserId();
        Boolean flag = userLocationApi.setLocation(latitude, longitude, addrStr, userId);
        if (!flag) {
            throw new BusinessException(ErrorResult.error());
        }
    }
}
